﻿using System;
using Abp.Castle.Logging.Log4Net;
using Abp.Web;
using Castle.Facilities.Logging;

namespace Sky.DispersedDemo.Web
{
    using Castle.Core.Logging;

    using Exceptionless;

    using StackExchange.Redis;

    public class MvcApplication : AbpWebApplication<DispersedDemoWebModule>
    {
        protected override void Application_Start(object sender, EventArgs e)
        {
            AbpBootstrapper.IocManager.IocContainer.AddFacility<LoggingFacility>(
                f => f.UseAbpLog4Net().WithConfig("log4net.config")
            );
            ExceptionlessClient.Default.Configuration.ApiKey="AaZa3oTGZtECKT5KDuhJrVE6GS6YLNT37RFrIjPn";
ExceptionlessClient.Default.Configuration.ServerUrl = "http://localhost:8004/";

            base.Application_Start(sender, e);
        }

        protected override void Application_BeginRequest(object sender, EventArgs e)
        {
            var logger = AbpBootstrapper.IocManager.Resolve<ILogger>();
            var info = GetRequestInfo();
            logger.InfoFormat(@"请求信息
{0}", info);

            base.Application_BeginRequest(sender, e);
        }

        private string GetRequestInfo()
        {
            var dt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
            var serverName = Server.MachineName;
            var serverIp = Request.ServerVariables["LOCAL_ADDR"];
            var serverPort = Request.ServerVariables["SERVER_PORT"];
            var PATH_TRANSLATED= Request.ServerVariables["PATH_TRANSLATED"];
            var requestIp = Request.Headers["X-Real-IP"];
            return string.Format(@"
请求日期:{0},
服务器名称:{1},
服务器IP:{2},
服务器端口:{3},
物理路径:{4},
请求者IP:{5}
",dt,serverName,serverIp, serverPort, PATH_TRANSLATED, requestIp);

            /* Label0.Text = "请求开始时间：" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            Label1.Text = "服务器名称：" + Server.MachineName;//服务器名称  
            Label2.Text = "服务器IP地址：" + Request.ServerVariables["LOCAL_ADDR"];//服务器IP地址  
            Label3.Text = "HTTP访问端口：" + Request.ServerVariables["SERVER_PORT"];//HTTP访问端口"
            Label4.Text = ".NET解释引擎版本：" + ".NET CLR" + Environment.Version.Major + "." + Environment.Version.Minor + "." + Environment.Version.Build + "." + Environment.Version.Revision;//.NET解释引擎版本  
            Label5.Text = "服务器操作系统版本：" + Environment.OSVersion.ToString();//服务器操作系统版本  
            Label6.Text = "服务器IIS版本：" + Request.ServerVariables["SERVER_SOFTWARE"];//服务器IIS版本  
            Label7.Text = "服务器域名：" + Request.ServerVariables["SERVER_NAME"];//服务器域名  
            Label8.Text = "虚拟目录的绝对路径：" + Request.ServerVariables["APPL_RHYSICAL_PATH"];//虚拟目录的绝对路径  
            Label9.Text = "执行文件的绝对路径：" + Request.ServerVariables["PATH_TRANSLATED"];//执行文件的绝对路径  
            Label10.Text = "虚拟目录Session总数：" + Session.Contents.Count.ToString();//虚拟目录Session总数  
            Label11.Text = "虚拟目录Application总数：" + Application.Contents.Count.ToString();//虚拟目录Application总数  
            Label12.Text = "域名主机：" + Request.ServerVariables["HTTP_HOST"];//域名主机  
            Label13.Text = "服务器区域语言：" + Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"];//服务器区域语言  
            Label14.Text = "用户信息：" + Request.ServerVariables["HTTP_USER_AGENT"];
            Label14.Text = "CPU个数：" + Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS");//CPU个数  
            Label15.Text = "CPU类型：" + Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER");//CPU类型  
            Label16.Text = "请求来源地址：" + Request.Headers["X-Real-IP"];*/
        }

    }
}
